package com.typy.www.tpay.ui.acitivity;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.AutoCompleteTextView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.typy.www.tpay.R;
import com.typy.www.tpay.base.BaseBackActivity;
import com.typy.www.tpay.bean.bean.BaseReturn;
import com.typy.www.tpay.bean.bean.HomeBtnBean;
import com.typy.www.tpay.bean.bean.PhotoOperation;
import com.typy.www.tpay.bean.listvm.GerPayListVm;
import com.typy.www.tpay.bean.vm.BankMsgVm;
import com.typy.www.tpay.bean.vm.GerPayVm;
import com.typy.www.tpay.constance.Constance;
import com.typy.www.tpay.constance.MessageEvent;
import com.typy.www.tpay.constance.Sharep;
import com.typy.www.tpay.net.sourceforge.simcpux.MD5;
import com.typy.www.tpay.ui.adapter.MineGridAdapter;
import com.typy.www.tpay.ui.dialog.SyDialogHelper;
import com.typy.www.tpay.ui.dialog.SyMessageDialog;
import com.typy.www.tpay.ui.prt.PtrScrollContent;
import com.typy.www.tpay.ui.view.HousePhotoOperationView;
import com.typy.www.tpay.util.CheckUtil;
import com.typy.www.tpay.util.ClassHoldUtil;
import com.typy.www.tpay.util.GsonUtils;
import com.typy.www.tpay.util.Logutil;
import com.typy.www.tpay.util.MediaFileUtil;
import com.typy.www.tpay.util.MessageAction;
import com.typy.www.tpay.util.ParamsUtil;
import com.typy.www.tpay.util.PreferencesUtil;
import com.typy.www.tpay.util.PwdDailogUtil;
import com.typy.www.tpay.util.ScollGridView;
import com.typy.www.tpay.util.StringUtil;
import com.typy.www.tpay.util.UiHelper;
import com.typy.www.tpay.util.UpdataUiUtil;
import com.typy.www.tpay.util.inter.InputCallBack;
import com.typy.www.tpay.util.listviewanimations.IntentUtil;
import com.typy.www.tpay.volley.HTTPUtils;
import com.typy.www.tpay.volley.VolleyListener;
import com.zhy.android.percent.support.PercentLinearLayout;

import org.greenrobot.eventbus.EventBus;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

/**
 * Created by 13799 on 2018/6/11.
 */

public class SuggestActivity extends BaseBackActivity implements UiHelper.TakePhotoListener, HousePhotoOperationView.HousePhotoOperationListener {

    @BindView(R.id.et_suggest)
    AutoCompleteTextView etSuggest;
    @BindView(R.id.tv_star)
    TextView tvStar;
    @BindView(R.id.tv_suggestshowhint)
    TextView tvSuggestshowhint;
    @BindView(R.id.publish)
    TextView publish;
    @BindView(R.id.tv_length)
    TextView tvLength;
    @BindView(R.id.img)
    ImageView img;
    @BindView(R.id.ll_photo)
    LinearLayout llPhoto;
    @BindView(R.id.et_beizhu)
    AutoCompleteTextView etBeizhu;
    @BindView(R.id.ll_hint)
    PercentLinearLayout llHint;
    @BindView(R.id.tv_miaosu)
    TextView tvMiaosu;
    @BindView(R.id.tv_queding)
    TextView tvQueding;
    @BindView(R.id.tv_quxiao)
    TextView tvQuxiao;
    @BindView(R.id.ll_buybtn)
    PercentLinearLayout llBuybtn;
    @BindView(R.id.tv_shoukuanrenxinxi)
    TextView tvShoukuanrenxinxi;
    @BindView(R.id.tv_dingdanhao)
    TextView tvDingdanhao;
    @BindView(R.id.et_dingdanhao)
    AutoCompleteTextView etDingdanhao;
    @BindView(R.id.ll_dingdanhao)
    PercentLinearLayout llDingdanhao;
    @BindView(R.id.tv_shishoujine)
    TextView tvShishoujine;
    @BindView(R.id.et_yingfujine)
    AutoCompleteTextView etYingfujine;
    @BindView(R.id.ll_yingfujine)
    PercentLinearLayout llYingfujine;
    @BindView(R.id.tv_zhifufangshi)
    TextView tvZhifufangshi;
    @BindView(R.id.et_chikarenxingming)
    AutoCompleteTextView etChikarenxingming;
    @BindView(R.id.ll_chikarenxingming)
    PercentLinearLayout llChikarenxingming;
    @BindView(R.id.tv_shoujihao)
    TextView tvShoujihao;
    @BindView(R.id.et_shoujihao)
    AutoCompleteTextView etShoujihao;
    @BindView(R.id.ll_shoujihao)
    PercentLinearLayout llShoujihao;
    @BindView(R.id.tv_kaihuyinhang)
    TextView tvKaihuyinhang;
    @BindView(R.id.et_kaihuyinhang)
    AutoCompleteTextView etKaihuyinhang;
    @BindView(R.id.ll_kaihuyinhang)
    PercentLinearLayout llKaihuyinhang;
    @BindView(R.id.tv_yinhangkahao)
    TextView tvYinhangkahao;
    @BindView(R.id.et_yinhangkahao)
    AutoCompleteTextView etYinhangkahao;
    @BindView(R.id.ll_yinhangkahao)
    PercentLinearLayout llYinhangkahao;
    @BindView(R.id.tv_zhihang)
    TextView tvZhihang;
    @BindView(R.id.et_zhihang)
    AutoCompleteTextView etZhihang;
    @BindView(R.id.ll_zhihang)
    PercentLinearLayout llZhihang;
    @BindView(R.id.tv_dingdanchuanjianshijian)
    TextView tvDingdanchuanjianshijian;
    @BindView(R.id.et_dingdanchuanjianshijian)
    AutoCompleteTextView etDingdanchuanjianshijian;
    @BindView(R.id.ll_dingdanchuanjianshijian)
    PercentLinearLayout llDingdanchuanjianshijian;
    @BindView(R.id.tv_dakuanhint)
    TextView tvDakuanhint;
    @BindView(R.id.ll_dakuanhint)
    PercentLinearLayout llDakuanhint;
    @BindView(R.id.ll_sell)
    PercentLinearLayout llSell;
    @BindView(R.id.ll_shoukuanrenholder)
    LinearLayout llShoukuanrenholder;
    @BindView(R.id.tv_shoukuanrenbeizhu)
    TextView tvShoukuanrenbeizhu;
    @BindView(R.id.et_shoukuanrenbeizhu)
    AutoCompleteTextView etShoukuanrenbeizhu;
    @BindView(R.id.ll_shoukuanrenbeizhu)
    PercentLinearLayout llShoukuanrenbeizhu;
    @BindView(R.id.tv_remark)
    TextView tvRemark;
    @BindView(R.id.ll_daishouholder)
    LinearLayout llDaishouholder;
    @BindView(R.id.ll_suggesthold)
    PercentLinearLayout llSuggesthold;
    @BindView(R.id.gv_mine)
    ScollGridView gvMine;
    @BindView(R.id.ll_dakuantitlehint)
    LinearLayout llDakuantitlehint;
    @BindView(R.id.tv_tupiantitle)
    TextView tvTupiantitle;
    private File hdFile;
    private int takePhotoType;
    private boolean isThumb;
    private int classType;
    private String orderId;
    private List<String> imgList = new ArrayList<>();
    private BankMsgVm bankMsgVm;
    private String pwd;
    private String detailUrl;
    private List<GerPayVm> gerPayVmList = new ArrayList<>();
    private MineGridAdapter adapter;
    private String fdContent;
    List<HomeBtnBean> mHomeList = new ArrayList<>();
    PtrScrollContent ptrScrollContent;
    private List<HousePhotoOperationView> photoViewList = new ArrayList<HousePhotoOperationView>();

    public static void show(Context context) {
        IntentUtil.intent2Activity(context, SuggestActivity.class);
    }

    public static void show(Context context, int classType, String OrderId) {
        Intent intent = new Intent();
        intent.putExtra("classType", classType);
        intent.putExtra("OrderId", OrderId);
        IntentUtil.intent2Activity(context, intent, SuggestActivity.class);
    }

    public static void show(Context context, int classType, String OrderId, String fdContent) {
        Intent intent = new Intent();
        intent.putExtra("classType", classType);
        intent.putExtra("OrderId", OrderId);
        intent.putExtra("fdContent", fdContent);
        IntentUtil.intent2Activity(context, intent, SuggestActivity.class);
    }

    @Override
    protected void initView() {
        super.initView();
        ButterKnife.bind(this);
        classType = getIntent().getIntExtra("classType", 0);
        orderId = getIntent().getStringExtra("OrderId");
        fdContent = getIntent().getStringExtra("OrderId");
        initTitle();
        etSuggest.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (s.length() >= 5) {
                    tvStar.setVisibility(View.INVISIBLE);
                    tvSuggestshowhint.setVisibility(View.INVISIBLE);
                } else {
                    tvStar.setVisibility(View.VISIBLE);
                    tvSuggestshowhint.setVisibility(View.VISIBLE);
                }
                tvLength.setText(s.length() + "/200");
            }
        });
        HousePhotoOperationView hpoView = new HousePhotoOperationView(this, 1, true);
        hpoView.setListener(this);
        hpoView.setShowShenHeTag(true);
        llPhoto.addView(hpoView.getView());
        photoViewList.add(hpoView);
    }

    private void initTitle() {
        if (classType == 0) {
            setTitle("投诉建议");
            ((TextView) mBtnRight).setText("我的回复");
            mBtnRight.setVisibility(View.VISIBLE);
            tvSuggestshowhint.setVisibility(View.VISIBLE);
            etSuggest.setVisibility(View.VISIBLE);
            etBeizhu.setVisibility(View.GONE);
            llHint.setVisibility(View.VISIBLE);
            llShoukuanrenholder.setVisibility(View.GONE);
            publish.setVisibility(View.VISIBLE);
            llBuybtn.setVisibility(View.GONE);
            tvMiaosu.setText(R.string.suggestimghint);
            llSuggesthold.setVisibility(View.VISIBLE);
            llDaishouholder.setVisibility(View.GONE);
            llPhoto.setVisibility(View.VISIBLE);
            gvMine.setVisibility(View.GONE);
        } else if (classType == ClassHoldUtil.DAKUAN) {
            setTitle("打款");
            mBtnRight.setVisibility(View.GONE);
            tvSuggestshowhint.setVisibility(View.GONE);
            etSuggest.setVisibility(View.GONE);
            etBeizhu.setVisibility(View.VISIBLE);
            llHint.setVisibility(View.GONE);
            llShoukuanrenholder.setVisibility(View.VISIBLE);
            publish.setVisibility(View.GONE);
            llBuybtn.setVisibility(View.VISIBLE);
            tvMiaosu.setText("上传打款凭证");
            tvQueding.setText("确定打款");
            tvQuxiao.setText("取消订单");
            llSuggesthold.setVisibility(View.VISIBLE);
            llDaishouholder.setVisibility(View.GONE);
            llPhoto.setVisibility(View.VISIBLE);
            gvMine.setVisibility(View.GONE);
            getbankmsg();
        } else if (classType == ClassHoldUtil.TOUSU) {
            setTitle("投诉");
            ((TextView) mBtnRight).setText("订单详情");
            mBtnRight.setVisibility(View.VISIBLE);
            tvSuggestshowhint.setVisibility(View.GONE);
            etSuggest.setVisibility(View.VISIBLE);
            etSuggest.setHint("请输入投诉内容");
            etBeizhu.setVisibility(View.GONE);
            llHint.setVisibility(View.GONE);
            llShoukuanrenholder.setVisibility(View.GONE);
            publish.setVisibility(View.VISIBLE);
            publish.setText("确认投诉");
            llBuybtn.setVisibility(View.GONE);
            tvMiaosu.setText("上传投诉图片");
            llDaishouholder.setVisibility(View.GONE);
            llSuggesthold.setVisibility(View.VISIBLE);
            llPhoto.setVisibility(View.VISIBLE);
            getOrderdetailurlURL();
            gvMine.setVisibility(View.GONE);
        } else if (classType == ClassHoldUtil.DAIQUERENSHOUKUAN) {
            setTitle(ClassHoldUtil.getClassTitle(classType));
            ((TextView) mBtnRight).setText("订单详情");
            mBtnRight.setVisibility(View.VISIBLE);
            tvSuggestshowhint.setVisibility(View.GONE);
            etSuggest.setVisibility(View.GONE);
            etBeizhu.setVisibility(View.GONE);
            llHint.setVisibility(View.GONE);
            llShoukuanrenholder.setVisibility(View.GONE);
            publish.setVisibility(View.GONE);
            tvQueding.setText("确认收款");
            tvQuxiao.setText("投诉");
            llDaishouholder.setVisibility(View.VISIBLE);
            llBuybtn.setVisibility(View.VISIBLE);
            llBuybtn.setBackgroundColor(getResources().getColor(R.color.app_bg));
            llDakuantitlehint.setVisibility(View.VISIBLE);
            tvMiaosu.setVisibility(View.GONE);
            llSuggesthold.setVisibility(View.GONE);
            llPhoto.setVisibility(View.GONE);
            tvRemark.setHint("对方打款备注");
            tvTupiantitle.setText("对方打款凭证");
            gvMine.setVisibility(View.VISIBLE);
            adapter = new MineGridAdapter(this);
            adapter.setmType(classType);
            gvMine.setAdapter(adapter);
            getOrderdetailurlURL();
            getGerpaymessageData();
        } else if (classType == ClassHoldUtil.TOUSUCHULIZHONG) {
            setTitle(ClassHoldUtil.getClassTitle(classType));
            ((TextView) mBtnRight).setText("订单详情");
            mBtnRight.setVisibility(View.VISIBLE);
            tvSuggestshowhint.setVisibility(View.GONE);
            etSuggest.setVisibility(View.GONE);
            etBeizhu.setVisibility(View.GONE);
            llHint.setVisibility(View.GONE);
            llShoukuanrenholder.setVisibility(View.GONE);
            publish.setVisibility(View.GONE);
            llDaishouholder.setVisibility(View.VISIBLE);
            llBuybtn.setVisibility(View.GONE);
            llBuybtn.setBackgroundColor(getResources().getColor(R.color.app_bg));
            tvMiaosu.setVisibility(View.GONE);
            llSuggesthold.setVisibility(View.GONE);
            llPhoto.setVisibility(View.GONE);
            gvMine.setVisibility(View.VISIBLE);
            adapter = new MineGridAdapter(this);
            adapter.setmType(classType);
            gvMine.setAdapter(adapter);
            llDakuantitlehint.setVisibility(View.GONE);
            tvTupiantitle.setText("投诉图片");
            tvRemark.setHint("投诉内容");
            getOrderdetailurlURL();
            getComplaintdetailURL();
        }
    }

    @Override
    protected void onRightButtonClick() {
        super.onRightButtonClick();
        if (classType == 0) {
            RecordActivity.show(getActivity(), ClassHoldUtil.SuggestRecord);
        } else {
            if (!StringUtil.isEmpty(detailUrl))
                WebActivity.show(getActivity(), "订单详情", detailUrl);
        }

    }

    @Override
    protected View getContentView() {
        ptrScrollContent = new PtrScrollContent(getActivity(), R.layout.activity_suggest) {
            @Override
            protected void getPage(int pageIndex, boolean refresh) {
                if (classType == ClassHoldUtil.DAKUAN)
                    getbankmsg();
                else
                    ptrScrollContent.loadInitialPage();
            }
        };
        return ptrScrollContent.getmView();
    }

    private void updataUi() {
        if (bankMsgVm != null) {
            UpdataUiUtil.getDefaul().setText(bankMsgVm.getFdOrderId(), etDingdanhao)
                    .setText(bankMsgVm.getFdMoney(), etYingfujine)
                    .setText(bankMsgVm.getFdBankUserName(), etChikarenxingming)
                    .setText(bankMsgVm.getFdCode(), etShoujihao)
                    .setText(bankMsgVm.getFdBankName(), etKaihuyinhang)
                    .setText(bankMsgVm.getFdBankNo(), etYinhangkahao)
                    .setText(bankMsgVm.getFdBranchName(), etZhihang)
                    .setText(bankMsgVm.getFdTradeTime(), etDingdanchuanjianshijian)
                    .setText(bankMsgVm.getFdRemark(), etShoukuanrenbeizhu);
        }
    }

    @OnClick({R.id.img, R.id.publish, R.id.tv_queding, R.id.tv_quxiao})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img:
//                UiHelper.showPhotoActionDlg(this, img, 1, null, this);
                break;
            case R.id.publish:
                imgList.clear();
                //避免连续点击时间
                if (UiHelper.isFastClick1000())
                    if (CheckUtil.checkText(getActivity(), etSuggest) && CheckUtil.checkText(getActivity(), "请输入至少5个字问题描述", 5, etSuggest)) {
                        UiHelper.showLoading(getActivity());
                        if (checkHasPhoto()) {
                            Logutil.print("有图片");
                            uploadPhotos(0);
                        } else {
                            SyDialogHelper.showAlertDlg(getActivity(), "请选择图片");
                            Logutil.print("有图片");
                            save();
                        }
                    }
                break;
            case R.id.tv_queding:
                imgList.clear();

                if (classType == ClassHoldUtil.DAKUAN) {
                    if (checkHasPhoto()) {
                        Logutil.print("有图片");

                        PwdDailogUtil.show((FragmentActivity) getActivity(), new InputCallBack() {
                            @Override
                            public void onInputFinish(String result) {
                                pwd = result;
                                UiHelper.showLoading(getActivity());
                                uploadPhotos(0);
                                PwdDailogUtil.hide();
                            }
                        });
                    } else {
                        SyDialogHelper.showAlertDlg(getActivity(), "请选择图片");
                    }
                } else if (classType == ClassHoldUtil.DAIQUERENSHOUKUAN) {

                    PwdDailogUtil.show((FragmentActivity) getActivity(), new InputCallBack() {
                        @Override
                        public void onInputFinish(String result) {
                            getSurereceiveData(result);
                        }
                    });

                }
                break;
            case R.id.tv_quxiao:
                if (classType == ClassHoldUtil.DAIQUERENSHOUKUAN) {
                    SuggestActivity.show(getActivity(), ClassHoldUtil.TOUSU, orderId);
                } else {
                    finish();
                }
                break;
        }
    }

    public void getSurereceiveData(String pwd) {
        ParamsUtil paramsUtil = new ParamsUtil();
        paramsUtil.put("fdOrderId", orderId);
        paramsUtil.putMd5("fdPayPwd", pwd);
        HTTPUtils.post(this, Constance.getSurereceiveURL(), paramsUtil.getParams(), new VolleyListener() {
            @Override
            public void onResponse(BaseReturn ret) {
                PwdDailogUtil.hide();
                SyDialogHelper.showDlg(getActivity(), "提示", "收款成功", "确定", new SyMessageDialog.OnClickListener() {
                    @Override
                    public void onClick(SyMessageDialog dialog) {
//                        EventBus.getDefault().post(new MessageEvent(MessageAction.CLOSERECORD));
                        RecordActivity.show(getActivity(), ClassHoldUtil.SELLYIWANCHENG);
                        finish();
                    }
                });
            }

            @Override
            public void onResponseErr(int code, String msg) {
                if (!Constance.WRONGPWD.equals(msg))
                    PwdDailogUtil.hide();
                UiHelper.showToast(getActivity(), msg);
            }
        });
    }

    public void save() {
        ParamsUtil paramsUtil = new ParamsUtil();
        String picList = "";
        for (int i = 0; i < imgList.size(); i++) {
            if (i < imgList.size() - 1) {
                picList += imgList.get(i) + ",";
            } else {
                picList += imgList.get(i);
            }
        }
        Logutil.print("IMGLIST==" + imgList.size());

        paramsUtil.put("picList", picList);
        String url = "";
        if (classType == 0) {
            paramsUtil.put("fdDesc", etSuggest);
            url = Constance.getSuggestsaveURL();
        } else if (classType == ClassHoldUtil.DAKUAN) {
            paramsUtil.putMd5("fdPayPwd", pwd);
            paramsUtil.put("fdOrderId", orderId);
            paramsUtil.put("fdPayRemark", etBeizhu);
            url = Constance.getBuypayURL();
        } else if (classType == ClassHoldUtil.TOUSU) {
            paramsUtil.put("fdOrderId", orderId);
            paramsUtil.put("fdContent", etSuggest);
            url = Constance.getComplaintURL();
        }

        HTTPUtils.post(this, url, paramsUtil.getParams(), new VolleyListener() {
            @Override
            public void onResponse(BaseReturn ret) {
                UiHelper.hideLoading();
                PwdDailogUtil.hide();
                EventBus.getDefault().post(new MessageEvent(MessageAction.REFEFRESHTOUSU));
                if (classType == 0) {
                    SyMessageDialog dlg = new SyMessageDialog(getActivity(),
                            SyMessageDialog.TYPE_INFORMATION).setTitleText(
                            "您的建议已提交成功").setPositiveButton("确定", null);
                    dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {

                        @Override
                        public void onDismiss(DialogInterface dialog) {
                            finish();
                        }

                    });
                    dlg.show();
                } else if (classType == ClassHoldUtil.DAKUAN) {
                    SyDialogHelper.showDlg(getActivity(), "提示", "提交成功", "确定", new SyMessageDialog.OnClickListener() {
                        @Override
                        public void onClick(SyMessageDialog dialog) {
                            EventBus.getDefault().post(new MessageEvent(MessageAction.REFRESHWEIWANCHENG));
                            RecordActivity.show(getActivity(), ClassHoldUtil.QUERENGDAKUANB);
                            finish();
                        }
                    });
                } else if (classType == ClassHoldUtil.TOUSU) {
                    SyDialogHelper.showDlg(getActivity(), "提示", "提交成功", "确定", new SyMessageDialog.OnClickListener() {
                        @Override
                        public void onClick(SyMessageDialog dialog) {
                            EventBus.getDefault().post(new MessageEvent(MessageAction.REFRESHWEIWANCHENG));
//                            RecordActivity.show(getActivity(), ClassHoldUtil.QUERENGDAKUANS);
                            finish();
                        }
                    });
                }
            }

            @Override
            public void onResponseErr(int code, String msg) {
                if (!Constance.WRONGPWD.equals(msg))
                    PwdDailogUtil.hide();
                UiHelper.showToast(getActivity(), msg);
                UiHelper.hideLoading();
            }
        });
    }

    //获取收款人信息
    private void getbankmsg() {
        ParamsUtil params = new ParamsUtil();
        params.put("fdOrderId", orderId);
        HTTPUtils.post(this, Constance.getGetreceivebankmsgURL(), params.getParams(), new VolleyListener() {
            @Override
            public void onResponse(BaseReturn ret) {
                ptrScrollContent.loadInitialPage();
                if (ret != null && ret.getData() != null) {
                    bankMsgVm = GsonUtils.parseJSON(ret.getData().toString(), BankMsgVm.class);
                    updataUi();
                }
            }

            @Override
            public void onResponseErr(int code, String msg) {
                ptrScrollContent.loadInitialPage();
            }
        });
    }

    //获取打款信息
    private void getGerpaymessageData() {
        ParamsUtil params = new ParamsUtil();
        params.put("fdOrderId", orderId);
        HTTPUtils.post(this, Constance.getGerpaymessageURL(), params.getParams(), new VolleyListener() {
            @Override
            public void onResponse(BaseReturn ret) {
                GerPayListVm listVm = GsonUtils.parseJSON(ret.getData().toString(), GerPayListVm.class);
                if (listVm != null) {
                    UpdataUiUtil.getDefaul().setText(listVm.getFdPayRemark(), tvRemark);
                    if (listVm.getImageList() != null && listVm.getImageList().size() > 0) {
                        gerPayVmList = listVm.getImageList();
                        for (GerPayVm vm : gerPayVmList) {
                            mHomeList.add(HomeBtnBean.getBean(vm.getFdPicUrl(), R.drawable.shouye_zhuanchu));
                        }
                        adapter.setList(mHomeList);
                        adapter.notifyDataSetChanged();
                    }
                }
            }

            @Override
            public void onResponseErr(int code, String msg) {

            }
        });
    }

    //投诉详情
    private void getComplaintdetailURL() {
        ParamsUtil params = new ParamsUtil();
        params.put("fdOrderId", orderId);
        params.put("fdContent", fdContent);
        HTTPUtils.post(this, Constance.getComplaintdetailURL(), params.getParams(), new VolleyListener() {
            @Override
            public void onResponse(BaseReturn ret) {
                GerPayListVm listVm = GsonUtils.parseJSON(ret.getData().toString(), GerPayListVm.class);
                if (listVm != null) {
                    UpdataUiUtil.getDefaul().setText(listVm.getFdContent(), tvRemark);
                    if (listVm.getImageList() != null && listVm.getImageList().size() > 0) {
                        gerPayVmList = listVm.getImageList();
                        for (GerPayVm vm : gerPayVmList) {
                            mHomeList.add(HomeBtnBean.getBean(vm.getFdPicUrl(), R.drawable.shouye_zhuanchu));
                        }
                        adapter.setList(mHomeList);
                        adapter.notifyDataSetChanged();
                    }
                }
            }

            @Override
            public void onResponseErr(int code, String msg) {

            }
        });
    }

    //获取订单详情
    private void getOrderdetailurlURL() {
        ParamsUtil params = new ParamsUtil();
        params.put("fdOrderId", orderId);
        HTTPUtils.post(this, Constance.getOrderdetailurlURL(), params.getParams(), new VolleyListener() {
            @Override
            public void onResponse(BaseReturn ret) {
                try {
                    detailUrl = ret.getData().getString("data");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onResponseErr(int code, String msg) {
                ptrScrollContent.loadInitialPage();
            }
        });
    }


    @Override
    public void onBeforeTakePhoto(boolean isThumb, File hdFile) {

    }

    @Override
    public void onPhotoChangeType(PhotoOperation po) {

    }

    @Override
    public void onTakePhoto(int photoType, boolean isThumb, File hdFile) {
        this.takePhotoType = photoType;
        this.isThumb = isThumb;
        this.hdFile = hdFile;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == HousePhotoOperationView.REQUEST_CODE_SELECTED_HOUSE_PHOTO
                && resultCode == Activity.RESULT_OK) {
            Object obj = data.getExtras().get(
                    ImageAddActivity.RESULT_SELECTED_IMAGES);
            int extraCode = data.getIntExtra(ImageAddActivity.EXTRA_CODE, 0);
            if (obj != null) {
                try {
                    @SuppressWarnings("unchecked")
                    ArrayList<File> files = (ArrayList<File>) obj;
                    for (HousePhotoOperationView hpoView : photoViewList) {
                        if (hpoView.getPhotoType() == extraCode) {
                            hpoView.setAddPhotoList(files);
                            break;
                        }
                    }
                } catch (Exception e) {
                }
            }
        } else if (requestCode == HousePhotoOperationView.REQUEST_CODE_TAKE_PHOTO
                && resultCode == Activity.RESULT_OK) {
            if (hdFile != null)
                addTakePhotoToView(1, hdFile);
        }
    }

    private void addTakePhotoToView(int photoType, File photo) {
        PhotoOperation po = new PhotoOperation();
        po.setType(photoType);
        po.setOperation(PhotoOperation.OPERATION_ADD);
        po.setPhoto(photo.toString());
        addPhotoOperationToView(po);
    }

    private void addTakePhotoToView(int photoType, String photo) {
        PhotoOperation po = new PhotoOperation();
        po.setType(photoType);
        po.setOperation(PhotoOperation.OPERATION_ADD);
        po.setPhoto(photo.toString());
        addPhotoOperationToView(po);
    }

    private void addPhotoOperationToView(PhotoOperation po) {
        for (HousePhotoOperationView hpov : photoViewList) {
            if (hpov.getPhotoType() == po.getType()) {
                hpov.addPhotoOperation(po);
                break;
            }
        }
    }

    private final MediaType MEDIA_TYPE_PNG = MediaType.parse("image/png");

    private void upImage(String url, int index, final boolean isLast) {
        final int i = ++index;
        MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder();
        multipartBodyBuilder.setType(MultipartBody.FORM);
        OkHttpClient mOkHttpClent = new OkHttpClient();
        String time = System.currentTimeMillis() + "";
        multipartBodyBuilder.addFormDataPart("token", PreferencesUtil.getValue(Sharep.TOKEN));
        multipartBodyBuilder.addFormDataPart("shx-timestamp", time);
        multipartBodyBuilder.addFormDataPart("shx-sign", a(time));
        File file = new File(url);
        if (!file.exists()) {
            return;
        }
        String name = url.substring(url.length() - 10, url.length());
        Logutil.print("name" + name);
        multipartBodyBuilder.addFormDataPart("file", name, RequestBody.create(MediaType.parse(MediaFileUtil.getFileTypes(url)), file));
        final RequestBody requestBody = multipartBodyBuilder.build();
        Request request = new Request.Builder()
                .url(Constance.getUploadURL())
                .post(requestBody)
                .build();
        Call call = mOkHttpClent.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Toast.makeText(getActivity(), "图片失败", Toast.LENGTH_SHORT).show();
                if (isLast) {
                    save();
                } else {
                    uploadPhotos(i);
                }
            }

            @Override
            public void onResponse(Call call, final Response response) throws IOException {
                if (response != null) {
                    if (response.body() != null) {
                        String str = response.body().string();
                        try {
                            JSONObject object = new JSONObject(str);
                            if (object != null) {
                                JSONObject obj = object.getJSONObject("data");
                                if (obj != null) {
//                                    String absolutePath = obj.getString("absolutePath");
                                    String path = obj.getString("path");
                                    Logutil.print("path==" + path);
                                    imgList.add(path);
                                }
                                if (isLast) {
                                    save();
                                } else {
                                    uploadPhotos(i);
                                }
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                            if (isLast) {
                                save();
                            } else {
                                uploadPhotos(i);
                            }
                        }
                    } else {
                        if (isLast) {
                            save();
                        } else {
                            uploadPhotos(i);
                        }
                    }
                }
            }
        });
    }

    public String a(String strTime) {
        Map<String, String> params = new HashMap<>();
        params.put("token", PreferencesUtil.getValue(Sharep.TOKEN));
        params.put("shx-timestamp", strTime);
        final List<Map.Entry<String, String>> list = new ArrayList<Map.Entry<String, String>>(params.entrySet());
        // 重写集合的排序方法：按字母顺序
        Collections.sort(list, new Comparator<Map.Entry<String, String>>() {
            @Override
            public int compare(Map.Entry<String, String> stringStringEntry, Map.Entry<String, String> t1) {
                return (stringStringEntry.getKey().toString().compareTo(t1.getKey()));
            }
        });
        StringBuilder builder = new StringBuilder();
        for (final Map.Entry<String, String> m : list) {
            if (!StringUtil.isEmpty(m.getValue()))
                builder.append(m.getKey()).append("=").append(m.getValue()).append("&");
        }
        builder.delete(builder.length() - 1, builder.length());
        builder.append(Constance.KEY);
        params.put("shx-sign", MD5.getMessageDigest(builder.toString().getBytes()));
        return MD5.getMessageDigest(builder.toString().getBytes());
    }

    private void uploadPhotos(int i) {
        HousePhotoOperationView hos = photoViewList.get(0);
        if (i < hos.getPhotoOperationList().size() - 1) {
            upImage(hos.getPhotoOperationList().get(i).getPhoto(), i, false);
        } else {
            upImage(hos.getPhotoOperationList().get(i).getPhoto(), i, true);
        }
    }

    private boolean checkHasPhoto() {
        HousePhotoOperationView hos = photoViewList.get(0);
        if (hos.getPhotoOperationList().size() == 0)
            return false;
        return true;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
